/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JPanel;

/**
 *
 * @author Pales
 */
public class CompSheetPanel extends JPanel {

    /**
     *  IDE FESTÜNK
     * két konstruktor: létrehozhat ilyet GraphicalController 
     * és Compositeview.
     * Ami lértrehozza, átadja magát, és elmentjük.
     * A létrehozott objektum elemeit rajzoljuk ki.
     * 
     * @author bg
     */
    private CompController graphicalController;

    public CompSheetPanel(CompController graphicalController) {
        this.graphicalController = graphicalController;
    }

    /**
     * Ez a cucc hívodíik meg festéskor. Itt kell mindenkit megkérni, hogy
     * fesse ki magát.
     * @param g
     */
    @Override
    public void paint(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D) g;

        g2d.setColor(Color.blue);

        for (int j = 0; j < 1500; j += 10) {
            for (int i = 0; i < 1200; i += 10) {
                int x = i;
                int y = j;
                g2d.drawLine(x, y, x, y);
            }
        }

        ArrayList<AbstractElementView> elements = graphicalController.getElements();
        ArrayList<WireView> wires = graphicalController.getWires();

        for (AbstractElementView element : elements) {
            element.tick();
            element.paint(g2d);

        }

        for (WireView wire : wires) {
            wire.paint(g2d);
        }

        for (Point inpoint : graphicalController.compositeinputs) {
            g2d.drawRect(inpoint.x - 5, inpoint.y - 5, 10, 10);
        }
        for (Point outpoint : graphicalController.compositeoutputs) {
            g2d.drawRect(outpoint.x - 5, outpoint.y - 5, 10, 10);
        }
    }
}
